package net.ciklum.svnnotify;

import java.util.ArrayList;
import java.util.List;


import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ChangedFilesActivity extends Activity {
	private List<String> items = new ArrayList<String>();
	private static ChangesListAdapter adapter = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notif_changes);

		items.add("One");
		items.add("Two");
		items.add("Three");
		items.add("0");
		items.add("1");
		items.add("2");
		items.add("3");
		items.add("4");
		items.add("5");
		items.add("6");
		items.add("7");
		items.add("8");
		items.add("9");
		items.add("10");
		items.add("11");
		items.add("12");

		adapter = new ChangesListAdapter(this, items);
		ListView notifList = (ListView) findViewById(R.id.changed_files);
		notifList.setAdapter(adapter);
		notifList.setTextFilterEnabled(true);


	}

	private class ListViewWrapper {
		private TextView changedFile = null;
		private View row = null;

		public ListViewWrapper(View row) {
			this.row = row;
		}

		public void populateFrom(String r) {
			getTitle().setText(r);
		}

		TextView getTitle() {
			if (changedFile == null) {
				changedFile = (TextView) row.findViewById(R.id.text);
			}
			return (changedFile);
		}

	}

	private class ChangesListAdapter extends ArrayAdapter<String> {

		private Activity activity;
		private List<String> items;

		public ChangesListAdapter(Activity activity, List<String> items) {
			super(activity, android.R.layout.simple_list_item_1, items);
			this.items = items;
			this.activity = activity;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			View row = convertView;
			ListViewWrapper wrapper = null;
			if (row == null) {
				LayoutInflater inflater = activity.getLayoutInflater();
				row = inflater.inflate(R.layout.list_item1, null);
				wrapper = new ListViewWrapper(row);
				row.setTag(wrapper);

			} else {
				wrapper = (ListViewWrapper) row.getTag();
			}

			wrapper.populateFrom(items.get(position));
			return (row);
		}

	}

}